﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

using Ninject;
using Cobisi.Web.MvcExtensions;

namespace SampleTryouts.Models
{
    public class HomeController : Controller
    {
        Product myProduct = new Product { ProductId = 1, Name = "Kayak", Description = "A boat for one person", Category = "Water Sports", Price = 125.34M };
        Product[] myProducts = {
                                   new Product { ProductId = 1, Name = "Kayak", Description = "A boat for one person", Category = "Water Sports", Price = 125.34M },
                                   new Product { ProductId = 2, Name = "Life Jacket", Description = "Saves a person's life", Category = "Water Sports", Price = 12.40M },
                                   new Product { ProductId = 3, Name = "Soccer ball", Description = "Have fun outside", Category = "Soccer", Price = 19.48M },
                                   new Product { ProductId = 4, Name = "Corner Flag", Description = "Mark the soccer field boundary lines", Category = "Soccerr", Price = 55.14M },
                               };
        //
        // GET: /Home/
        [Route("~/Home-tmp")] // using Cboisi MVC extensions..
        public ActionResult Index()
        {
            return View(myProduct);
        }

        public ActionResult DemoArray()
        {
            Product[] productArray = { new Product { Name = "Corner flag", Price = 23.33M }, new Product { Name = "Soccer Ball", Price = 11.45M } };
            return View(productArray);
        }

        // Ninject IoC; modify the constructor
        private IValueCalculator Calc;
        //private IShoppingCart Cart;
        public HomeController(IValueCalculator calcParam
            //, IShoppingCart cartParam
            )
        {
            Calc = calcParam;
            //Cart = cartParam;
        }

        public ActionResult CalculateProductTotal()
        {
            //// Ninject fuctionality...
            //IKernel ninjectKernel = new StandardKernel();
            //ninjectKernel.Bind<IValueCalculator>().To<LinqValueCalculator>(); // But still our controller class has to be aware of the LinqValueCalculator
            //// Better IoC/DI is done under the Infrastructure folder in this project.
            //IValueCalculator calc = ninjectKernel.Get<IValueCalculator>(); // IoC/DI using ninject binding

            // IValueCalculator calc = new LinqValueCalculator(); // No IoC/DI used here, very bad design. Not usable for unit-testing or for Mocks :-(
            //ShoppingCart cart = new ShoppingCart(calc) { Products = myProducts };

            ShoppingCart cart = new ShoppingCart(Calc) { Products = myProducts };
            var Total = cart.CalculateProductTotal();
            return View(Total);
        }
    }
}
